<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
      #app {
        width: 400px;
        height: 200px;
        background-color: antiquewhite;
        margin: 0 auto;
        text-align: center;
      }
      #app input {
        width: 270px;
        height: 30px;
        margin: 20px 0;
      }
      #app button {
        width: 250px;
        height: 35px;
        border-radius: 20px;
        background-color: #e3251d;
      }
      .opt {
        opacity: 0.5;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <input type="text" v-model="val" placeholder="用户名/邮箱/手机号" /><span
        @click="del()"
        v-show="flag"
        >X</span
      >
      <br />

      <button @click="btn()" :disabled="dis" :class="{opt:dis}">登录</button>
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          val: "",
          //删除
          flag: false,
          //btn是否禁用
          dis: true,
        },
        watch: {
          val(newValue) {
            if (newValue.length > 0) {
              this.flag = true;
              if (newValue.length == 11) {
                this.dis = false;
              } else {
                this.dis = true;
              }
            } else {
              this.flag = false
            }
          },
        },
        methods: {
          del() {
            this.val = "";
          },
          btn() {
            console.log("登录");
          },
        },
      });
    </script>
  </body>
</html>
